package com.bytedance.frameworks.a.d;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView.ItemDecoration;
import android.support.v7.widget.RecyclerView.State;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public final class a extends ItemDecoration {
    public int a;
    private static final int[] b;
    private Drawable c;
    private boolean d;
    private int e;

    static {
        b = new int[]{16843284};
    }

    public a(Context arg4) {
        this.d = true;
        TypedArray v0 = arg4.obtainStyledAttributes(b);
        this.c = v0.getDrawable(0);
        if (this.c != null) {
            this.a = this.c.getIntrinsicHeight();
        }
        v0.recycle();
        this.e = 1;
    }

    public final void a(Drawable arg2) {
        this.c = arg2;
        if (this.c.getIntrinsicHeight() > 0) {
            this.a = this.c.getIntrinsicHeight();
        }
    }

    public final void getItemOffsets(Rect arg4, View arg5, RecyclerView arg6, State arg7) {
        if (this.e == 1) {
            int v0 = arg6.getChildAdapterPosition(arg5);
            if (v0 != 0 && v0 == arg7.getItemCount() - 1) {
                v0 = this.d ? this.a : 0;
                arg4.set(0, 0, 0, v0);
                return;
            }

            arg4.set(0, 0, 0, this.a);
        } else {
            arg4.set(0, 0, this.a, 0);
        }
    }

    public final void onDraw(Canvas arg8, RecyclerView arg9, State arg10) {
        int v0;
        View v5;
        int v4;
        int v3;
        int v2;
        if (this.e == 1) {
            v2 = arg9.getPaddingLeft();
            v3 = arg9.getWidth() - arg9.getPaddingRight();
            v4 = arg9.getChildCount();
            int v1;
            for (v1 = 0; v1 < v4; ++v1) {
                v5 = arg9.getChildAt(v1);
                v0 = ((RecyclerView.LayoutParams) v5.getLayoutParams()).bottomMargin + v5.getBottom();
                this.c.setBounds(v2, v0, v3, this.a + v0);
                this.c.draw(arg8);
            }
        } else {
            v2 = arg9.getPaddingTop();
            v3 = arg9.getHeight() - arg9.getPaddingBottom();
            v4 = arg9.getChildCount();
            for (int v1 = 0; v1 < v4; ++v1) {
                v5 = arg9.getChildAt(v1);
                v0 = ((RecyclerView.LayoutParams) v5.getLayoutParams()).rightMargin + v5.getRight();
                this.c.setBounds(v0, v2, this.a + v0, v3);
                this.c.draw(arg8);
            }
        }
    }
}

